mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/TACOS.git
synced 2025-06-12 09:36:00 +00:00
92 lines
1.8 KiB
C++
92 lines
1.8 KiB
C++
#ifndef STA_TACOS_WATCHDOG_HPP
|
|
#define STA_TACOS_WATCHDOG_HPP
|
|
|
|
#include <sta/config.hpp>
|
|
#ifdef STA_TACOS_WATCHDOG_ENABLED
|
|
|
|
#ifndef STA_TACOS_WATCHDOG_PRIORITY
|
|
# error "TACOS watchdog priority was not specified!"
|
|
#endif // STA_TACOS_WATCHDOG_PRIORITY
|
|
|
|
#ifndef STA_TACOS_WATCHDOG_FREQUENCY
|
|
# error "TACOS watchdog frequency was not specified!"
|
|
#endif // STA_TACOS_WATCHDOG_FREQUENCY
|
|
|
|
|
|
#include <sta/tacos/thread.hpp>
|
|
|
|
|
|
/**
|
|
* @defgroup tacos_watchdog Watchdog Task
|
|
* @ingroup tacos
|
|
* @brief Watchdog class for TACOS.
|
|
*/
|
|
|
|
namespace sta
|
|
{
|
|
namespace tacos
|
|
{
|
|
/**
|
|
* @brief Watchdog class for TACOS using singleton pattern.
|
|
*
|
|
* @ingroup tacos_watchdog
|
|
*/
|
|
class Watchdog: public TacosThread
|
|
{
|
|
public:
|
|
/**
|
|
* @brief Getter for the singleton instance. Constructs the instance if no exists.
|
|
*
|
|
* @ingroup tacos_watchdog
|
|
*/
|
|
static Watchdog* instance()
|
|
{
|
|
static CGuard g;
|
|
|
|
if (!_instance)
|
|
{
|
|
// Create the watchdog singleton instance.
|
|
Watchdog::_instance = new Watchdog();
|
|
}
|
|
|
|
return _instance;
|
|
}
|
|
|
|
void func() override;
|
|
|
|
/**
|
|
* @brief Get the number of thread restarts during the program's runtime.
|
|
*
|
|
* @return uint16_t The number of thread restarts.
|
|
*/
|
|
uint16_t getNumRestarts();
|
|
private:
|
|
static Watchdog* _instance;
|
|
|
|
class CGuard
|
|
{
|
|
public:
|
|
~CGuard()
|
|
{
|
|
if( NULL != Watchdog::_instance )
|
|
{
|
|
delete Watchdog::_instance;
|
|
Watchdog::_instance = NULL;
|
|
}
|
|
}
|
|
};
|
|
|
|
Watchdog();
|
|
|
|
Watchdog(const Watchdog&);
|
|
|
|
~Watchdog() {}
|
|
private:
|
|
uint16_t restarts_;
|
|
};
|
|
} // namespace tacos
|
|
} // namespace sta
|
|
|
|
#endif // STA_TACOS_WATCHDOG_ENABLED
|
|
|
|
#endif // STA_TACOS_WATCHDOG_HPP
|