better reset handling
All checks were successful
EIVE/eive-obsw/pipeline/pr-develop This commit looks good

This commit is contained in:
Robin Müller 2023-04-14 19:42:11 +02:00
parent 8cf9dd9136
commit e023220be4
No known key found for this signature in database
GPG Key ID: 11D4952C8CCEF814
2 changed files with 27 additions and 18 deletions

View File

@ -156,7 +156,7 @@ ReturnValue_t PdecHandler::polledOperation() {
// See https://yurovsky.github.io/2014/10/10/linux-uio-gpio-interrupt.html for more information. // See https://yurovsky.github.io/2014/10/10/linux-uio-gpio-interrupt.html for more information.
ReturnValue_t PdecHandler::irqOperation() { ReturnValue_t PdecHandler::irqOperation() {
ReturnValue_t result = returnvalue::OK; ReturnValue_t result = returnvalue::OK;
int fd = -1; // int fd = -1;
// Used to unmask IRQ // Used to unmask IRQ
uint32_t info = 1; uint32_t info = 1;
@ -176,7 +176,7 @@ ReturnValue_t PdecHandler::irqOperation() {
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
break; break;
} }
openIrqFile(&fd); openIrqFile();
if (ptmeResetWithReinitializationPending) { if (ptmeResetWithReinitializationPending) {
actionHelper.finish(true, commandedBy, pdec::RESET_PDEC_WITH_REINIITALIZATION); actionHelper.finish(true, commandedBy, pdec::RESET_PDEC_WITH_REINIITALIZATION);
ptmeResetWithReinitializationPending = false; ptmeResetWithReinitializationPending = false;
@ -195,7 +195,7 @@ ReturnValue_t PdecHandler::irqOperation() {
} }
case State::RUNNING: { case State::RUNNING: {
doPeriodicWork(); doPeriodicWork();
checkAndHandleIrqs(fd, info); checkAndHandleIrqs(info);
break; break;
} }
case State::WAIT_FOR_RECOVERY: case State::WAIT_FOR_RECOVERY:
@ -236,9 +236,9 @@ ReturnValue_t PdecHandler::handleInitState() {
return returnvalue::OK; return returnvalue::OK;
} }
void PdecHandler::openIrqFile(int* fd) { void PdecHandler::openIrqFile() {
*fd = open(uioNames.irq, O_RDWR); irqFd = open(uioNames.irq, O_RDWR);
if (*fd < 0) { if (irqFd < 0) {
sif::error << "PdecHandler::irqOperation: Opening UIO IRQ file" << uioNames.irq << " failed" sif::error << "PdecHandler::irqOperation: Opening UIO IRQ file" << uioNames.irq << " failed"
<< std::endl; << std::endl;
triggerEvent(OPEN_IRQ_FILE_FAILED); triggerEvent(OPEN_IRQ_FILE_FAILED);
@ -246,16 +246,16 @@ void PdecHandler::openIrqFile(int* fd) {
} }
} }
ReturnValue_t PdecHandler::checkAndHandleIrqs(int fd, uint32_t& info) { ReturnValue_t PdecHandler::checkAndHandleIrqs(uint32_t& info) {
ssize_t nb = write(fd, &info, sizeof(info)); ssize_t nb = write(irqFd, &info, sizeof(info));
if (nb != static_cast<ssize_t>(sizeof(info))) { if (nb != static_cast<ssize_t>(sizeof(info))) {
sif::error << "PdecHandler::irqOperation: Unmasking IRQ failed" << std::endl; sif::error << "PdecHandler::irqOperation: Unmasking IRQ failed" << std::endl;
triggerEvent(WRITE_SYSCALL_ERROR_PDEC, errno); triggerEvent(WRITE_SYSCALL_ERROR_PDEC, errno);
close(fd); close(irqFd);
state = State::INIT; state = State::INIT;
return returnvalue::FAILED; return returnvalue::FAILED;
} }
struct pollfd fds = {.fd = fd, .events = POLLIN, .revents = 0}; struct pollfd fds = {.fd = irqFd, .events = POLLIN, .revents = 0};
int ret = poll(&fds, 1, IRQ_TIMEOUT_MS); int ret = poll(&fds, 1, IRQ_TIMEOUT_MS);
if (ret == 0) { if (ret == 0) {
// No TCs for timeout period // No TCs for timeout period
@ -263,7 +263,7 @@ ReturnValue_t PdecHandler::checkAndHandleIrqs(int fd, uint32_t& info) {
resetIrqLimiters(); resetIrqLimiters();
} else if (ret >= 1) { } else if (ret >= 1) {
// Interrupt handling. // Interrupt handling.
nb = read(fd, &info, sizeof(info)); nb = read(irqFd, &info, sizeof(info));
interruptCounter++; interruptCounter++;
if (nb == static_cast<ssize_t>(sizeof(info))) { if (nb == static_cast<ssize_t>(sizeof(info))) {
uint32_t pisr = *(registerBaseAddress + PDEC_PISR_OFFSET); uint32_t pisr = *(registerBaseAddress + PDEC_PISR_OFFSET);
@ -302,7 +302,7 @@ ReturnValue_t PdecHandler::checkAndHandleIrqs(int fd, uint32_t& info) {
sif::error << "PdecHandler::irqOperation: Poll error with errno " << errno << ": " sif::error << "PdecHandler::irqOperation: Poll error with errno " << errno << ": "
<< strerror(errno) << std::endl; << strerror(errno) << std::endl;
triggerEvent(POLL_SYSCALL_ERROR_PDEC, errno); triggerEvent(POLL_SYSCALL_ERROR_PDEC, errno);
close(fd); close(irqFd);
state = State::INIT; state = State::INIT;
return returnvalue::FAILED; return returnvalue::FAILED;
} }
@ -347,7 +347,7 @@ ReturnValue_t PdecHandler::executeAction(ActionId_t actionId, MessageQueueId_t c
return EXECUTION_FINISHED; return EXECUTION_FINISHED;
} }
case RESET_PDEC_WITH_REINIITALIZATION: { case RESET_PDEC_WITH_REINIITALIZATION: {
state = State::PDEC_RESET; initializeReset();
ptmeResetWithReinitializationPending = true; ptmeResetWithReinitializationPending = true;
this->commandedBy = commandedBy; this->commandedBy = commandedBy;
return returnvalue::OK; return returnvalue::OK;
@ -380,7 +380,7 @@ ReturnValue_t PdecHandler::getParameter(uint8_t domainId, uint8_t uniqueIdentifi
return returnvalue::FAILED; return returnvalue::FAILED;
} }
// PDEC needs reset to apply this parameter change // PDEC needs reset to apply this parameter change
state = State::PDEC_RESET; initializeReset();
return returnvalue::OK; return returnvalue::OK;
} else if ((domainId == 0) and (uniqueIdentifier == ParameterId::NEGATIVE_WINDOW)) { } else if ((domainId == 0) and (uniqueIdentifier == ParameterId::NEGATIVE_WINDOW)) {
uint8_t newVal = 0; uint8_t newVal = 0;
@ -402,7 +402,7 @@ ReturnValue_t PdecHandler::getParameter(uint8_t domainId, uint8_t uniqueIdentifi
return returnvalue::FAILED; return returnvalue::FAILED;
} }
// PDEC needs reset to apply this parameter change // PDEC needs reset to apply this parameter change
state = State::PDEC_RESET; initializeReset();
return returnvalue::OK; return returnvalue::OK;
} }
return returnvalue::OK; return returnvalue::OK;
@ -797,6 +797,13 @@ ReturnValue_t PdecHandler::postResetOperation() {
return result; return result;
} }
void PdecHandler::initializeReset() {
if (irqFd != 0) {
close(irqFd);
}
state = State::PDEC_RESET;
}
std::string PdecHandler::getMonStatusString(uint32_t status) { std::string PdecHandler::getMonStatusString(uint32_t status) {
switch (status) { switch (status) {
case TC_CHANNEL_INACTIVE: case TC_CHANNEL_INACTIVE:

View File

@ -171,6 +171,7 @@ class PdecHandler : public SystemObject,
Countdown genericCheckCd = Countdown(IRQ_TIMEOUT_MS); Countdown genericCheckCd = Countdown(IRQ_TIMEOUT_MS);
object_id_t tcDestinationId; object_id_t tcDestinationId;
int irqFd = 0;
AcceptsTelecommandsIF* tcDestination = nullptr; AcceptsTelecommandsIF* tcDestination = nullptr;
@ -243,8 +244,8 @@ class PdecHandler : public SystemObject,
ReturnValue_t polledOperation(); ReturnValue_t polledOperation();
ReturnValue_t irqOperation(); ReturnValue_t irqOperation();
ReturnValue_t handleInitState(); ReturnValue_t handleInitState();
void openIrqFile(int* fd); void openIrqFile();
ReturnValue_t checkAndHandleIrqs(int fd, uint32_t& info); ReturnValue_t checkAndHandleIrqs(uint32_t& info);
uint32_t readFar(); uint32_t readFar();
@ -366,6 +367,7 @@ class PdecHandler : public SystemObject,
void pdecResetNoInit(); void pdecResetNoInit();
ReturnValue_t postResetOperation(); ReturnValue_t postResetOperation();
void initializeReset();
void initFailedHandler(ReturnValue_t reason); void initFailedHandler(ReturnValue_t reason);