~aleteoryx/muditaos

390a22363720b53e7182c05cd4109b1f4cc1ab3c — Alek Rudnik 4 years ago 457d877
[EGD-8154] Added watchdog thread closure on system exit

Made sure that watchdog thread is properly closed while exiting OS.
M module-os/FreeRTOS/include/FreeRTOSConfig.h => module-os/FreeRTOS/include/FreeRTOSConfig.h +1 -1
@@ 131,7 131,7 @@ extern "C"
#define INCLUDE_xTaskGetIdleTaskHandle       1
#define INCLUDE_eTaskGetState                0
#define INCLUDE_xTimerPendFunctionCall       1
#define INCLUDE_xTaskAbortDelay              0
#define INCLUDE_xTaskAbortDelay              1
#define INCLUDE_xTaskGetHandle               0
#define INCLUDE_xTaskResumeFromISR           1


M module-os/board/rt1051/systemview/FreeRTOSConfig.h => module-os/board/rt1051/systemview/FreeRTOSConfig.h +1 -1
@@ 125,7 125,7 @@ extern "C"
#define INCLUDE_xTaskGetIdleTaskHandle       1
#define INCLUDE_eTaskGetState                0
#define INCLUDE_xTimerPendFunctionCall       1
#define INCLUDE_xTaskAbortDelay              0
#define INCLUDE_xTaskAbortDelay              1
#define INCLUDE_xTaskGetHandle               0
#define INCLUDE_xTaskResumeFromISR           1


M module-sys/SystemWatchdog/SystemWatchdog.cpp => module-sys/SystemWatchdog/SystemWatchdog.cpp +18 -3
@@ 1,4 1,4 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include <SystemWatchdog/SystemWatchdog.hpp>


@@ 34,6 34,7 @@ namespace sys
        }
        bsp::watchdog::refresh();

        enableRunLoop = true;
        if (!Start()) {
            return false;
        }


@@ 54,8 55,8 @@ namespace sys

    void SystemWatchdog::Run()
    {
        while (true) {
            vTaskDelay(checkPeriod);
        while (enableRunLoop) {
            Delay(checkPeriod);

            if (timeout_occurred) {
                continue;


@@ 71,5 72,19 @@ namespace sys
                bsp::watchdog::refresh();
            }
        }

        // notify caller of deinit()
        taskEndedSem.Give();
    }

    void SystemWatchdog::deinit()
    {
#ifndef DISABLE_WATCHDOG
        enableRunLoop = false;
        xTaskAbortDelay(GetHandle());
        if (!taskEndedSem.Take(closurePeriod)) {
            LOG_ERROR("Watchdog thread was not gently closed, killing");
        }
#endif
    }
} // namespace sys

M module-sys/SystemWatchdog/include/SystemWatchdog/SystemWatchdog.hpp => module-sys/SystemWatchdog/include/SystemWatchdog/SystemWatchdog.hpp +10 -3
@@ 1,4 1,4 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once


@@ 36,6 36,9 @@ namespace sys

        void refresh() override;

        // It doesn't disable watchdog, but it simply close the petting thread
        void deinit();

      private:
        SystemWatchdog();



@@ 45,11 48,15 @@ namespace sys
        static constexpr TickType_t watchdogTimeoutPeriod = pdMS_TO_TICKS(16000);
        // Period of actual watchdog refresh
        static constexpr TickType_t checkPeriod = pdMS_TO_TICKS(8000);
        // Timeout period for watchdog thread closure
        static constexpr TickType_t closurePeriod = pdMS_TO_TICKS(2000);

        void Run() final;

        TickType_t lastRefreshTimestamp = 0;
        bool timeout_occurred           = false;
        TickType_t lastRefreshTimestamp{0};
        bool timeout_occurred{false};
        bool enableRunLoop{false};
        cpp_freertos::BinarySemaphore taskEndedSem{false};

        static_assert(sizeof(lastRefreshTimestamp) == 4 && alignof(decltype(lastRefreshTimestamp)) == 4,
                      "SystemWatchdog::lastRefreshTimestamp must be 32-bit long and properly aligned otherwise data "

M products/BellHybrid/BellHybridMain.cpp => products/BellHybrid/BellHybridMain.cpp +2 -1
@@ 1,4 1,4 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "PlatformFactory.hpp"


@@ 133,6 133,7 @@ int main()
                LOG_FATAL("%s", e.what());
                abort();
            }
            sys::SystemWatchdog::getInstance().deinit();
            return true;
        });


M products/PurePhone/PurePhoneMain.cpp => products/PurePhone/PurePhoneMain.cpp +1 -0
@@ 219,6 219,7 @@ int main()
                LOG_FATAL("%s", e.what());
                abort();
            }
            sys::SystemWatchdog::getInstance().deinit();
            return true;
        });