2023-10-02 14:15:50 +02:00
|
|
|
#include "XiphosWdtHandler.h"
|
|
|
|
|
|
|
|
XiphosWdtHandler::XiphosWdtHandler(object_id_t objectId) : SystemObject(objectId) {}
|
|
|
|
|
|
|
|
ReturnValue_t XiphosWdtHandler::initialize() {
|
|
|
|
int result = xsc_watchdog_init(&wdtHandle);
|
|
|
|
if (result != 0) {
|
|
|
|
sif::error << "XiphosWdtHandler: Initiating watchdog failed with code " << result << ": "
|
|
|
|
<< strerror(result) << std::endl;
|
|
|
|
return ObjectManagerIF::CHILD_INIT_FAILED;
|
|
|
|
}
|
|
|
|
if (wdtHandle == nullptr) {
|
|
|
|
sif::error << "XiphosWdtHandler: WDT handle is nullptr!" << std::endl;
|
|
|
|
return ObjectManagerIF::CHILD_INIT_FAILED;
|
|
|
|
}
|
|
|
|
result = xsc_watchdog_set_timeout(wdtHandle, timeoutSeconds);
|
|
|
|
if (result != 0) {
|
2023-10-02 14:49:29 +02:00
|
|
|
// This propably means that the default timeout is used. Still continue with task init.
|
|
|
|
sif::warning << "XiphosWdtHandler: Setting WDT timeout of " << timeoutSeconds
|
2023-10-02 14:15:50 +02:00
|
|
|
<< " seconds failed with code " << result << ": " << strerror(result) << std::endl;
|
|
|
|
}
|
2023-10-02 14:47:41 +02:00
|
|
|
int nowayout = 0;
|
|
|
|
int status = 0;
|
|
|
|
result = xsc_watchdog_get_status(&nowayout, &status);
|
|
|
|
if (result == 0) {
|
|
|
|
if (status == 0) {
|
|
|
|
result = xsc_watchdog_enable(wdtHandle);
|
|
|
|
if (result != 0) {
|
|
|
|
sif::error << "XiphosWdtHandler: Enabling WDT failed with code " << result << ": "
|
|
|
|
<< strerror(result) << std::endl;
|
|
|
|
return ObjectManagerIF::CHILD_INIT_FAILED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
sif::warning << "XiphosWdtHandler: Getting WDT status failed" << std::endl;
|
2023-10-02 14:15:50 +02:00
|
|
|
}
|
|
|
|
return returnvalue::OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t XiphosWdtHandler::performOperation(uint8_t opCode) {
|
|
|
|
int result = xsc_watchdog_keepalive(wdtHandle);
|
|
|
|
if (result != 0) {
|
|
|
|
sif::warning << "XiphosWdtHandler: Feeding WDT failed with code " << result << ": "
|
|
|
|
<< strerror(result) << std::endl;
|
|
|
|
return returnvalue::FAILED;
|
|
|
|
}
|
|
|
|
return returnvalue::OK;
|
|
|
|
}
|