From c06dd15303331429b781843a65cb8a4d8f427f9e Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Mon, 27 Feb 2023 11:35:43 +0100 Subject: [PATCH] minor bugfix in PDEC Handler --- linux/ipcore/PdecHandler.cpp | 33 +++++++++++++++++++++------------ linux/ipcore/PdecHandler.h | 8 ++++++-- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/linux/ipcore/PdecHandler.cpp b/linux/ipcore/PdecHandler.cpp index db93bd6e..80327c94 100644 --- a/linux/ipcore/PdecHandler.cpp +++ b/linux/ipcore/PdecHandler.cpp @@ -164,13 +164,8 @@ ReturnValue_t PdecHandler::polledOperation() { // See https://yurovsky.github.io/2014/10/10/linux-uio-gpio-interrupt.html for more information. ReturnValue_t PdecHandler::irqOperation() { - int fd = open(uioNames.irq, O_RDWR); - if (fd < 0) { - sif::error << "PdecHandler::irqOperation: Opening UIO IRQ file" << uioNames.irq << " failed" - << std::endl; - return returnvalue::FAILED; - } - + ReturnValue_t result = returnvalue::OK; + int fd = -1; // Used to unmask IRQ uint32_t info = 1; @@ -186,11 +181,14 @@ ReturnValue_t PdecHandler::irqOperation() { readCommandQueue(); switch (state) { case State::INIT: { - handleInitState(); + result = handleInitState(); + if (result == returnvalue::OK) { + openIrqFile(&fd); + } break; } case State::PDEC_RESET: { - ReturnValue_t result = pdecToReset(); + result = pdecToReset(); if (result != returnvalue::OK) { triggerEvent(PDEC_RESET_FAILED); } @@ -217,7 +215,7 @@ ReturnValue_t PdecHandler::irqOperation() { return returnvalue::OK; } -void PdecHandler::handleInitState() { +ReturnValue_t PdecHandler::handleInitState() { ReturnValue_t result = firstLoop(); if (result != returnvalue::OK) { if (result == LocalParameterHandler::SD_NOT_READY) { @@ -227,15 +225,26 @@ void PdecHandler::handleInitState() { "becomes ready" << std::endl; state = State::WAIT_FOR_RECOVERY; - return; } else { state = State::INIT; - return; } + return result; } state = State::WAIT_FOR_RECOVERY; + return result; } state = State::RUNNING; + return returnvalue::OK; +} + +void PdecHandler::openIrqFile(int* fd) { + *fd = open(uioNames.irq, O_RDWR); + if (*fd < 0) { + sif::error << "PdecHandler::irqOperation: Opening UIO IRQ file" << uioNames.irq << " failed" + << std::endl; + triggerEvent(OPEN_IRQ_FILE_FAILED); + state = State::WAIT_FOR_RECOVERY; + } } ReturnValue_t PdecHandler::checkAndHandleIrqs(int fd, uint32_t& info) { diff --git a/linux/ipcore/PdecHandler.h b/linux/ipcore/PdecHandler.h index d3507211..e98e939c 100644 --- a/linux/ipcore/PdecHandler.h +++ b/linux/ipcore/PdecHandler.h @@ -101,9 +101,12 @@ class PdecHandler : public SystemObject, static constexpr Event POLL_SYSCALL_ERROR_PDEC = event::makeEvent(SUBSYSTEM_ID, 8, severity::MEDIUM); static constexpr Event WRITE_SYSCALL_ERROR_PDEC = - event::makeEvent(SUBSYSTEM_ID, 9, severity::MEDIUM); + event::makeEvent(SUBSYSTEM_ID, 9, severity::HIGH); //! [EXPORT] : [COMMENT] Failed to pull PDEC reset to low static constexpr Event PDEC_RESET_FAILED = event::makeEvent(SUBSYSTEM_ID, 10, severity::HIGH); + //! [EXPORT] : [COMMENT] Failed to open the IRQ uio file + static constexpr Event OPEN_IRQ_FILE_FAILED = + event::makeEvent(SUBSYSTEM_ID, 11, severity::HIGH); private: static const uint8_t INTERFACE_ID = CLASS_ID::PDEC_HANDLER; @@ -279,7 +282,8 @@ class PdecHandler : public SystemObject, ReturnValue_t polledOperation(); ReturnValue_t irqOperation(); - void handleInitState(); + ReturnValue_t handleInitState(); + void openIrqFile(int* fd); ReturnValue_t checkAndHandleIrqs(int fd, uint32_t& info); uint32_t readFar();